home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5592 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: in2.uu.net!peach!atl1!mikec
  2. From: mikec@atl1.america.net (Michael J. Callahan)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Aborting Constructors, Part II
  5. Date: 3 Feb 1996 08:28:37 -0500
  6. Organization: Access America(TM), P.O. Box 1222, Alpharetta, GA 30239-1222
  7. Message-ID: <mikec.823353055@atl1>
  8. References: <4eoeck$t6n@news.ios.com> <4eq99t$fpu@fsuj01.rz.uni-jena.de> <marnoldDM529E.3CH@netcom.com>
  9. NNTP-Posting-Host: atl1.america.net
  10. X-Newsreader: NN version 6.5.0 #3 (NOV)
  11.  
  12. >>Problem 2:  The language already provides an automatic call to delete
  13. >>if you throw an exception from an object that was allocated using new.
  14. >>The code above would cause delete to be called twice!  Once again, heap
  15. >>corruption is likely.
  16. >>
  17.  
  18. Now how did I miss that? Through my reading I try to keep abreast of 
  19. stds, as they evolve, but I profess ignorance of the above point. Could
  20. you elaborate on this a little more?
  21.  
  22. It sounds as if you are saying that the raw memory allocated for the
  23. ctor to be run against is automatically freed by virtue of an exception
  24. being thrown within a ctor. Of course this seems to mean that exceptions
  25. have to treat their invocation differently from within ctors, as versus
  26. other placement positions in code, which implies more knowledge than I 
  27. thought an exception had. It also seems to imply that once you have thrown
  28. an exception in a ctor, that object no longer exists (if indeed the raw
  29. memory for the object has automatically and unconditionly been deallocated).
  30. I must confess I have never tried to test/access an object that threw an
  31. exception in its ctor to see whether the object was just an invalid instance
  32. or actually no longer existed.
  33.  
  34. So under the covers, a new allocates raw memory for the object to occupy, 
  35. and begins running the ctor on that raw memory. Within the ctor, if an
  36. exception is thrown, the raw memory allocation if deallocated, the instance
  37. in effect no longer exists?
  38.  
  39. Is that recent behavior to the evolving std, or did I just miss it? If 
  40. recent, is it implemented in many compilers yet?
  41.  
  42. Anyone else???
  43. -------------------------------
  44. |\/|ike C. -- mikec@america.net 
  45. *note: insert clever tagline here...         
  46.  
  47.  
  48.  
  49.